package com.wl.week_01;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import static org.apache.poi.ss.usermodel.CellType.*;

/**
 * 练习使用POI处理Excel表格
 * @author TaiZai
 * @data 2024/9/27 14:13
 */
public class Dome_4 {
    private static List<User_Demo_4> userList = new ArrayList<>();
    public static void main(String[] args) {
        // 1、引入外部的jar包

        // 2、加载Excel文件  首先创建加载Excel文件的对象
        try (
                Workbook workbook = new XSSFWorkbook(new FileInputStream("src/main/resources/user.xlsx"));
                ) {
            // 利用 workbook 对象进行 Excel 信息的解析
            Sheet sheet = workbook.getSheetAt(0); // 获取第一个Sheet页

            // 循环遍历 sheet 页面总共cell
            int index = 0;
            for (Row row : sheet) {
                if(index++ == 0) continue;
                User_Demo_4 user = new User_Demo_4(
                        Integer.valueOf(row.getCell(0).toString()), row.getCell(1).toString(),
                        row.getCell(2).toString(), row.getCell(3).toString(),
                        row.getCell(4).toString(), row.getCell(5).toString(),
                        row.getCell(6).toString()
                );
                userList.add(user);
            }
            for (User_Demo_4 user : userList) {
                System.out.println(user.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
